//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "ExtendedOrnsteinUhlenbeckProcess.h"
using namespace Cephei::QL::Experimental::Processes;
#include <gen/QL/Math/Array.h>
#include <gen/QL/StochasticProcess1D.h>
using namespace Cephei::QL::Math;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::CExtendedOrnsteinUhlenbeckProcess (boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess>& childNative, Object^ owner) : CStochasticProcess1D(CExtendedOrnsteinUhlenbeckProcess::typeid)
{
#ifdef HANDLE
	_phExtendedOrnsteinUhlenbeckProcess = NULL;
#endif
	_ppExtendedOrnsteinUhlenbeckProcess = &childNative;
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppExtendedOrnsteinUhlenbeckProcess));
}
Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::CExtendedOrnsteinUhlenbeckProcess (QuantLib::ExtendedOrnsteinUhlenbeckProcess& childNative, Object^ owner) : CStochasticProcess1D(CExtendedOrnsteinUhlenbeckProcess::typeid)
{
#ifdef HANDLE
	_phExtendedOrnsteinUhlenbeckProcess = NULL;
#endif
	_ppExtendedOrnsteinUhlenbeckProcess = new boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess> (&childNative);
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppExtendedOrnsteinUhlenbeckProcess));
    _ExtendedOrnsteinUhlenbeckProcessOwner = owner;
    _StochasticProcess1DOwner = owner;
}

Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::CExtendedOrnsteinUhlenbeckProcess (CExtendedOrnsteinUhlenbeckProcess^ copy) : CStochasticProcess1D(CExtendedOrnsteinUhlenbeckProcess::typeid)
{
#ifdef HANDLE
	_phExtendedOrnsteinUhlenbeckProcess = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppExtendedOrnsteinUhlenbeckProcess = new boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess> (copy->GetShared());
        _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppExtendedOrnsteinUhlenbeckProcess));
    }
}
Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::CExtendedOrnsteinUhlenbeckProcess (PLATFORM::Type^ t) : CStochasticProcess1D(CExtendedOrnsteinUhlenbeckProcess::typeid)
{
#ifdef HANDLE
	_phExtendedOrnsteinUhlenbeckProcess = NULL;
#endif
	if (!t->IsSubclassOf(CExtendedOrnsteinUhlenbeckProcess::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::CExtendedOrnsteinUhlenbeckProcess (QuantLib::Handle<QuantLib::ExtendedOrnsteinUhlenbeckProcess>& childNative, Object^ owner)  : CStochasticProcess1D(CExtendedOrnsteinUhlenbeckProcess::typeid)
{
	_phExtendedOrnsteinUhlenbeckProcess = &childNative;
	_ppExtendedOrnsteinUhlenbeckProcess = &static_cast<boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess>>(childNative.currentLink());
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppExtendedOrnsteinUhlenbeckProcess));
    _ExtendedOrnsteinUhlenbeckProcessOwner = owner;
}
Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::CExtendedOrnsteinUhlenbeckProcess (QuantLib::Handle<QuantLib::ExtendedOrnsteinUhlenbeckProcess> childNative)  : CStochasticProcess1D(CExtendedOrnsteinUhlenbeckProcess::typeid)
{
	_phExtendedOrnsteinUhlenbeckProcess = &childNative;
	_ppExtendedOrnsteinUhlenbeckProcess = &static_cast<boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess>>(childNative.currentLink());
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppExtendedOrnsteinUhlenbeckProcess));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::CExtendedOrnsteinUhlenbeckProcess (QuantLib::ExtendedOrnsteinUhlenbeckProcess childNative)  : CStochasticProcess1D(CExtendedOrnsteinUhlenbeckProcess::typeid)
{
#ifdef HANDLE
	_phExtendedOrnsteinUhlenbeckProcess = NULL;
#endif
	_ppExtendedOrnsteinUhlenbeckProcess = new boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess> (new QuantLib::ExtendedOrnsteinUhlenbeckProcess (childNative));
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppExtendedOrnsteinUhlenbeckProcess));
}
#endif

Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::~CExtendedOrnsteinUhlenbeckProcess ()
{
    if (_ppExtendedOrnsteinUhlenbeckProcess != NULL)
    {
	    delete _ppExtendedOrnsteinUhlenbeckProcess;
        _ppExtendedOrnsteinUhlenbeckProcess = NULL;
    }
}
Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::!CExtendedOrnsteinUhlenbeckProcess ()
{
    if (_ppExtendedOrnsteinUhlenbeckProcess != NULL)
    {
	    delete _ppExtendedOrnsteinUhlenbeckProcess;
    }
}
QuantLib::ExtendedOrnsteinUhlenbeckProcess& Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::GetReference ()
{
    if (_ppExtendedOrnsteinUhlenbeckProcess == NULL) throw REFNEW NativeNullException ();
	return **_ppExtendedOrnsteinUhlenbeckProcess;
}
boost::shared_ptr<QuantLib::ExtendedOrnsteinUhlenbeckProcess>& Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::GetShared ()
{
    if (_ppExtendedOrnsteinUhlenbeckProcess == NULL) throw REFNEW NativeNullException ();
	return *_ppExtendedOrnsteinUhlenbeckProcess;
}
QuantLib::ExtendedOrnsteinUhlenbeckProcess* Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::GetPointer ()
{
    if (_ppExtendedOrnsteinUhlenbeckProcess == NULL) throw REFNEW NativeNullException ();
	return &**_ppExtendedOrnsteinUhlenbeckProcess;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ExtendedOrnsteinUhlenbeckProcess>& Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::GetHandle ()
{
	if (_phExtendedOrnsteinUhlenbeckProcess == NULL)
	{
		_phExtendedOrnsteinUhlenbeckProcess = new Handle<QuantLib::ExtendedOrnsteinUhlenbeckProcess> (*_ppExtendedOrnsteinUhlenbeckProcess);
	}
	return *_phExtendedOrnsteinUhlenbeckProcess;
}
#endif
bool Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::HasNative () 
{
	return (_ppExtendedOrnsteinUhlenbeckProcess != NULL);
}

Double Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::Diffusion (Double t, Double x)
{
    try
    {
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t); //a
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtendedOrnsteinUhlenbeckProcess)->diffusion ( _t,  _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::Drift (Double t, Double x)
{
    try
    {
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t); //a
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtendedOrnsteinUhlenbeckProcess)->drift ( _t,  _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::Expectation (Double t0, Double x0, Double dt)
{
    try
    {
        QuantLib::Time _t0 = (QuantLib::Time)ValueHelper::Convert (t0); //a
        QuantLib::Real _x0 = (QuantLib::Real)ValueHelper::Convert (x0); //a
        QuantLib::Time _dt = (QuantLib::Time)ValueHelper::Convert (dt); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtendedOrnsteinUhlenbeckProcess)->expectation ( _t0,  _x0,  _dt );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::Speed::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtendedOrnsteinUhlenbeckProcess)->speed ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::StdDeviation (Double t0, Double x0, Double dt)
{
    try
    {
        QuantLib::Time _t0 = (QuantLib::Time)ValueHelper::Convert (t0); //a
        QuantLib::Real _x0 = (QuantLib::Real)ValueHelper::Convert (x0); //a
        QuantLib::Time _dt = (QuantLib::Time)ValueHelper::Convert (dt); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtendedOrnsteinUhlenbeckProcess)->stdDeviation ( _t0,  _x0,  _dt );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::Variance (Double t0, Double x0, Double dt)
{
    try
    {
        QuantLib::Time _t0 = (QuantLib::Time)ValueHelper::Convert (t0); //a
        QuantLib::Real _x0 = (QuantLib::Real)ValueHelper::Convert (x0); //a
        QuantLib::Time _dt = (QuantLib::Time)ValueHelper::Convert (dt); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtendedOrnsteinUhlenbeckProcess)->variance ( _t0,  _x0,  _dt );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::Volatility::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtendedOrnsteinUhlenbeckProcess)->volatility ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Processes::CExtendedOrnsteinUhlenbeckProcess::X0::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppExtendedOrnsteinUhlenbeckProcess)->x0 ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

